package com.example.a10928.weifriend.http.configuration;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.Date;

/**
 * Created by Chuang on 2018/2/26.
 * 转换JSON中的Date为long型的时间秒数;
 * Retrofit中的查询参数中的Date, 使用{@link DateFieldConverterFactory}转换
 * <p>
 * Created by ipcjs on 2017/05/22.
 */

public class DateTypeAdapter extends TypeAdapter<Date> {
    public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
        @Override
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
            if (type.getRawType() == Date.class)
                return (TypeAdapter<T>) new DateTypeAdapter().nullSafe();
            return null;
        }
    };

    @Override
    public void write(JsonWriter out, Date value) throws IOException {

    }

    @Override
    public Date read(JsonReader in) throws IOException {
        return null;
    }
}
